<template>
  <div class="exhibits-info-top" ref="scrollIntoView" id="tem1-scroll-box-top">
    <div class="heard-box" v-if="info">
      <span></span>
      <div class="heard-left">
        <div class="left-top">
          <!-- <a
            class="Icon-3d"
            :style="{
              backgroundImage: `url(${
                ImgUrlCancat + '/template/template13Dicon' + store.styleInfo.colorType + '.png'
              })`,
            }"
            :href="info.externalUrl"
            v-if="info.externalUrl"
          >
          </a> -->
          <t-image
            :style="{
              backgroundColor: store.styleInfo.auxiliaryColor,
            }"
            @click="open(imgUrl)"
            v-if="imgUrl"
            class="left-top-img"
            fit="contain"
            position="center"
            :src="$filters.getLinkUrl(imgUrl + '?imageView2/0/w/375/format/webp')"
            alt=""
          />
        </div>
      </div>
      <div class="left-btm" v-if="info.images?.length > 1">
        <!-- <div class="item-title1">展品图片</div> -->
        <div
          class="left-content"
          id="scroll-by-box"
          :style="{ justifyContent: info.images?.length > 4 ? 'flex-start' : 'center' }"
        >
          <div
            @click="lookIndex(index)"
            class="scroll-item"
            v-for="(item, index) in info.images"
            :key="index"
            :id="`scroll-child-${index}`"
            :class="{ 'img-active': current == index }"
          >
            <div class="img-shadow">
              <span v-if="item.type == 1">正立面</span>
              <span v-else-if="item.type == 2">侧立面</span>
              <span v-else-if="item.type == 3">顶面</span>
              <span v-else-if="item.type == 4">底面</span>
              <span v-else-if="item.type == 5">侧面</span>
              <span v-else>未设置</span>
            </div>
            <t-image
              class="scroll-item-img"
              :src="$filters.getLinkUrl(item.data + '?imageView2/1/w/50/format/webp')"
              alt=""
            />
          </div>
        </div>
      </div>
      <div class="heard-right">
        <div class="right-item-level">
          <span>{{ info.name }}</span>
          <!-- <img src="https://static.jiyi.show/assets/img/level1.png" alt="" v-if="info.levelValue == '一级文物'" />
        <img src="https://static.jiyi.show/assets/img/level2.png" alt="" v-else-if="info.levelValue == '二级文物'" />
        <img src="https://static.jiyi.show/assets/img/level3.png" alt="" v-else-if="info.levelValue == '三级文物'" />
        <img src="https://static.jiyi.show/assets/img/level0.png" alt="" v-else /> -->
        </div>
        <div>
          <div class="right-item" v-if="info.typeValue">
            <span class="item-title1">展品类型</span><span class="item-title2">{{ info.typeValue }}</span>
          </div>
          <div class="right-item" v-if="info.sourceValue">
            <span class="item-title1">展品来源</span
            ><span class="item-title2">{{ info.sourceValue ? info.sourceValue : '--' }}</span>
          </div>
          <div class="right-item" v-if="info.ageIds">
            <span class="item-title1">所属年代</span
            ><span class="item-title2">{{ info.ageIds ? info.ageIds : '--' }}</span>
          </div>
          <div class="right-item" v-if="info.companyName">
            <span class="item-title1">收藏单位</span
            ><span class="item-title2">{{ info.companyName ? info.companyName : '--' }}</span>
          </div>
          <div class="right-item" v-if="info.texture">
            <span class="item-title1">展品质地</span
            ><span class="item-title2">{{ info.texture ? info.texture : '--' }}</span>
          </div>
          <div class="right-item" v-if="info.levelValue">
            <span class="item-title1">展品等级</span
            ><span class="item-title2">{{ info.levelValue ? info.levelValue : '--' }}</span>
          </div>
          <div class="right-item" v-if="info.size">
            <span class="item-title1">展品尺寸</span><span class="item-title2">{{ info.size ? info.size : '--' }}</span>
          </div>
        </div>
      </div>
    </div>
    <div v-if="info.description || (info.audio && info.audio.url)" class="describe-box">
      <div class="dot">
        <p class="describe-title">展品描述</p>
      </div>
      <div class="audeo-parent" v-if="info.audio && info.audio.url">
        <playAudio :name="info.audio.name" :url="info.audio.url" />
      </div>
      <!-- <div class="describe-text" v-html="info.description"></div> -->
      <div v-html="info.description" class="describe-text"></div>
    </div>
    <div class="exhibits-list">
      <p class="describe-title">相关展品</p>
      <exhibitsInfoList :list="scrollBoxList" @emitItemId="lookExibit" />
      <!-- <div class="list-content">
        <div
          class="exhibits-item"
          :class="{ 'exhibits-item-1': (index + 1) % 2 === 0 }"
          v-for="(item, index) in scrollBoxList"
          :key="index"
        >
          <div class="item-content" @click="lookExibit(item.id)">
            <div class="item-cover">
              <img :src="$filters.getLinkUrl(item.coverUrl, '?imageView2/3/format/webp')" alt="" />
            </div>
            <div class="btm-name" :style="{ backgroundImage: `url(${publicUrls + 'customized/zjz/unitIcon21.png'})` }">
              <span>{{ item.name }}</span>
            </div>
          </div>
          <img
            v-if="index % 2 === 0"
            class="wrapper-title-img3"
            :src="publicUrls + 'customized/zjz/unitIcon20.png'"
            alt=""
          />
        </div>
      </div> -->
    </div>

    <NavVue :flag="true"></NavVue>
  </div>
  <van-image-preview v-model="visible" :images="info.images" @change="onChange"> </van-image-preview>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
  name: 'templateExhibitsInfoLoopWap',
});
</script>
<script setup lang="ts">
// @ts-nocheck
import exhibitsInfoList from './exhibitsInfoList.vue';
import { publicUrls } from '@/utils/minxin';
import { moduleShowpieces } from '@/api/exhibit/exhibit';
import { filterHTML } from '@/utils/minxin';
import { colorList } from '@/pages/templatePage/data';
import { ImgUrlCancat } from '@/utils/minxin';
import playAudio from '@/wap/wapPage/wapComponents/publicComponents/wapComponents/auxiliarys/audio.vue';
import { urls } from '@/utils/request/upload';
import { onActivated, onMounted, ref, watch, nextTick, reactive } from 'vue';
import { MessagePlugin } from 'tdesign-vue-next';
import { useProjectStore, getExhibitStore } from '@/store';
import { followSet } from '@/api/interact/interact';
import arrowLeft from './arrowLeft.vue';
import arrowRight from './arrowRight.vue';
import { handlemouse, getTrimText } from '@/utils/minxin';
import dotIcon from './dotIcon.vue';
import { useRoute } from 'vue-router';
import { exhibitShowpiece } from '@/api/templates/templates';
import exhibitVue from '../exhibitsInfo.vue';
import messageModel from '@/components/messageModel/index.vue';
import { getHeardToken } from '@/api/utils';
import { projectLists } from '@/api/project/project';
import { addExhibits } from '@/api/desgin/desgin';
import shear from '@/components/shear/shear.vue';
import { toQQzone, toQQ, toWeibo, toWechat } from '@/utils/shear';
import NavVue from './nav.vue';
import { outLogin, doorUrl } from '@/utils/minxin';
import { getLinkUrl } from '@/utils/request/upload';
import { showImagePreview } from 'vant';
const storeExhibit = getExhibitStore();
const countNum = ref(false);
const route = useRoute();
const store = useProjectStore();
const imgUrl = ref('');
const visible = ref(false);
const viewerIndex = ref(0);
const scrollBoxList = ref([]);
const parmas = reactive({
  pageSize: 99,
  pageNo: 1,
  id: 0,
  value: '',
  filterId: 0,
});
const urlList = ref([]);
const selectList = ref(null);
const info: any = ref({});
const current = ref(0);
const descriptionShow = ref(true);
const loading = ref(false);
const visibleStep = ref(false);
const projectId = ref(null);
const scrollIntoView = ref(null);
const visibleMessage1 = ref(false);
// const emit = defineEmits(['changeattention']);
const getImgurl = (e: any) => {
  if (e.indexOf('https://') !== -1) {
    return e;
  } else {
    return urls + e;
  }
};
const closetables = (context?: any): void => {
  visibleStep.value = false;
};
const init = async () => {
  try {
    // console.log(showpieceid.value);
    descriptionShow.value = false;
    let { data } = await exhibitShowpiece(moduleId.value, showpieceid.value);
    info.value = data;
    info.value.images.unshift({
      data: info.value.coverUrl,
      type: -1,
    });
    urlList.value = [];
    // //console.log(info.value.followTotal, 'followTotal');

    urlList.value.push(getImgurl(info.value.coverUrl));

    imgUrl.value = info.value.coverUrl;

    descriptionShow.value = true;
    initList();
  } catch {
    descriptionShow.value = true;
  }
  // find();
};
const initList = async () => {
  try {
    parmas.filterId = showpieceid.value;
    moduleShowpieces(localStorage.getItem('projectId'), parmas).then((res) => {
      scrollBoxList.value = res.data.data;
    });
  } catch {}
};
const lookExibit = (e: number) => {
  scrollIntoView.value.scrollIntoView();
  showpieceid.value = e;
  init();
};
const getAudioColor = (type: number) => {
  //设置背景色
  let color = '';
  switch (type) {
    case 1:
      color = 'rgba(250, 249, 247, .3)';
      break;
    case 2:
      color = 'rgba(250, 251, 252, .3)';
      break;
    case 3:
      color = 'rgba(252, 251, 250, .3)';
      break;
    case 4:
      color = 'rgba(245, 245, 245, .3)';
      break;
    default:
      color = 'rgba(247, 247, 247, .3)';
      break;
  }
  return color;
};
const object: any = ref({});

const moduleId = ref(0);
const showpieceid = ref(0);
moduleId.value = Number(route.query.moduleId);
parmas.id = Number(route.query.moduleId);
showpieceid.value = Number(route.query.id);
init();
// const open = (e: any) => {
//   visible.value = true;

// };
const open = (e) => {
  let previewList = info.value.images;
  let imageUrls = previewList.map((item) => getLinkUrl(item.data + ''));
  console.log(imageUrls);

  showImagePreview({
    images: imageUrls,
    startPosition: current.value, // 设置起始位置，默认为第一张图片（索引为0）
  });
};
const putcurrent = (type: number, index: Number) => {
  if (type == 1 && current.value !== 0) {
    current.value = current.value - 1;
  } else if (type === 2 && current.value !== info.value.images.length - 1) {
    current.value = current.value + 1;
  }
  //console.log(`scroll-child-${current.value}`);
  let ele = document.getElementById(`scroll-child-${current.value}`);
  ele.scrollIntoView({ behavior: 'smooth', block: 'center' });
  imgUrl.value = info.value.images[current.value].data;
  // ele.scrollIntoView();
};
const lookIndex = (e: number) => {
  current.value = e;
  // let ele = document.getElementById(`scroll-child-${current.value}`);
  // ele.scrollIntoView({ behavior: 'smooth', block: 'center' });
  imgUrl.value = info.value.images[current.value].data;
};
// watch(
//   () => route.query.id,
//   () => {
//     // console.log('route', route.query);
//     if (route.query.id) {
//       showpieceid.value = Number(route.query.id);
//       moduleId.value = Number(route.query.moduleId);
//       init();
//     }
//   },
//   { deep: true },
// );
watch(
  () => showpieceid.value,
  () => {
    // init();
    // console.log('showpieceid变化', showpieceid.value);
  },
  { deep: true },
);

// const find = () => {
//   //console.log('route', storeExhibit.ExhibitList);

//   const targetExhibit = storeExhibit.ExhibitList.filter((exhibit) => exhibit.id == showpieceid.value);
//   if (targetExhibit.length > 0) {
//     countNum.value = 1;
//   } else {
//     countNum.value = 0;
//   }
// };

watch(
  () => storeExhibit.ExhibitList,
  () => {
    //console.log('storeExhibit', storeExhibit.ExhibitList);
    // find();
  },
  { immediate: true, deep: true },
);

// 添加关注事件

const emitAddInfo = () => {
  storeExhibit.pushExhibitInfo(info.value);
};
const emitchangeExhi = (info: any) => {
  //console.log(info);

  showpieceid.value = info;
  init();
};
onMounted(() => {
  const element = document.getElementById('tem1-scroll-box-top');
  // console.log('element---', element);

  element.scrollIntoView({ block: 'start' });
});
onActivated(() => {
  const element = document.getElementById('tem1-scroll-box-top');
  // console.log('element---', element);

  element.scrollIntoView({ block: 'start' });
  if (route.query.id) {
    showpieceid.value = Number(route.query.id);
    moduleId.value = Number(route.query.moduleId);
    init();
  }
});
</script>

<style lang="less" scoped>
.exhibits-info-top {
  padding: 50px 0px;
  padding-bottom: 0px;
  min-height: calc(100vh - 28px);
  background: #f1e8d6;
}
.dot {
  height: 30px;
  // line-height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;

  font-size: 18px;
  color: #a2463c;
  line-height: 30px;
  font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
}
.describe-title {
  text-align: center;
  font-size: 18px;
  color: #a2463c;
  line-height: 30px;
  font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
}

.describe-box {
  padding-top: 24px;
  padding-bottom: 24px;

  .describe-text {
    width: 100%;
    margin: 0 auto;
    margin-top: 8px;
    font-size: 16px;
    // font-family: SourceHanSerifCN-Medium, SourceHanSerifCN;
    font-weight: 400;
    color: #333333;
    line-height: 32px;
    // margin-bottom: 20px;
    font-family: none;
    text-align: justify;
    :deep(*) {
      text-indent: 2em;
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      font-size: 16px;
      color: #333333;
      line-height: 32px;
      // margin-top: 24px;
    }
    :deep(div) {
      font-family: none;
      text-indent: 2em;
    }
  }
}
.copyright-box {
  //   padding: 50px 130px;
}

.t-row {
  margin: 0;
}

.heard-box {
  // display: flex;
  width: 100%;
  margin: 0 auto;
}

.heard-left {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.left-top {
  width: 100%;
  height: 300px;
  position: relative;

  .left-top-img {
    width: 100%;
    height: 300px;
    background: #f1e8d6;
  }
}
.Icon-3d {
  display: flex;
  cursor: pointer;
  position: absolute;
  top: -2px;
  right: 16px;
  width: 40px;
  height: 52px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  z-index: 10;
}
.heard-right {
  // flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;

  // margin-left: 16px;
  width: 100%;
  padding: 0 16px;
}

.right-item {
  display: flex;
  // align-items: center;
  width: 100%;
  margin-bottom: 10px;
}

.item-title1 {
  font-size: 14px;
  // font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #aaaaaa;
  line-height: 22px;
  // width: 56px;
}

.item-title2 {
  display: flex;
  flex: 1;
  font-size: 16px;
  // font-family: SourceHanSerifCN-Medium, SourceHanSerifCN;
  font-weight: 400;
  color: #333333;
  line-height: 22px;
  margin-left: 16px;
  // opacity: 0.59;
}

.right-item-level {
  font-size: 18px;
  font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
  line-height: 26px;
  color: #333333;
  // line-height: 42px;

  img {
    width: 72px;
    height: 20px;
    margin-left: 18px;
  }

  margin-bottom: 16px;
  margin-top: 16px;
}

.btn-box {
  display: flex;
  margin-top: 20px;
  margin-bottom: 19px;
}

.add-btn {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50%;
  height: 56px;
  background: #cfbda8;
  font-size: 16px;
  // font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 24px;

  img {
    width: 40px;
    height: 40px;
    // margin-left: 6px;
  }
}

.add-btn1 {
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  width: 56px;
  height: 56px;
  font-size: 24px;
}

// .add-btn1:hover {
//   background: #f0e9e1;
// }
.left-btm {
  display: flex;
  align-items: center;
  height: 76px;
  background: #f0e1c1;
  // background: #fff;
}

.left-btm-chevron {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 3px;
}

.left-content {
  display: flex;
  flex: 1;
  height: 58px;
  margin: 0 12px;
  overflow: hidden;
  overflow-x: auto;
  scrollbar-width: none;
  // flex-wrap: wrap;
  // overflow-y: hidden;
  // min-width: 500px;
}

.scroll-item {
  cursor: pointer;
  position: relative;
  // width: 56px;
  // height: 56px;
  padding: 1px;
  border: 1px solid transparent;
  margin-right: 10px;
  flex-wrap: wrap;
  padding: 3px;
  .scroll-item-img {
    width: 50px;
    height: 50px;
  }
}
.scroll-item:nth-child(5n) {
  margin-right: 0px;
}
.img-shadow {
  display: none;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
  background: rgba(0, 0, 0, 0.4);
  font-size: 16px;
  // font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 24px;
}

.img-active {
  border: 1px solid rgba(162, 70, 60, 0.6);
}

.zoomIn {
  width: 40px;
  height: 40px;
  cursor: pointer;
  position: absolute;
  top: 20px;
  right: 24px;
  z-index: 0;
  font-size: 20px;
  color: #fff;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  transition: all 0.3s;
  > .t-icon {
    font-size: 24px;
    position: relative;
    top: 50%;
    left: 60%;
    transform: translate(-50%, -50%);
  }
}
// .zoomIn:hover {
//   opacity: 70%;
// }
.t-image__wrapper {
  background: #f0e9e1;
  z-index: 0;
}

.exhibit {
  width: 336px;
  height: 56px;
  text-align: center;
  color: #fff;
  line-height: 56px;
  cursor: pointer;
  margin-left: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  i {
    margin-top: 2px;
  }
}
// .exhibit:hover {
//   opacity: 0.7;
// }

.audeo-parent {
  width: 100%;
  margin-bottom: 16px;
}
.exhibits-list {
  padding: 0 16px;
  .describe-title {
    margin-bottom: 8px;
  }
}
</style>
